home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Amiga Plus Special 12
/
Amiga Plus Sonderheft Amiga 12.iso
/
pd
/
spiele
/
klondike_adptools
/
install
/
datas
/
english.lha
/
3-MakeGlobalPalette.adpro
< prev
next >
Wrap
Text File
|
1997-08-22
|
15KB
|
690 lines
/*
** MakeGlobalPalette.adpro :
**
** This ARexx script for ADPro v2.5 or higher,
** load some previously scaled pictures (IFF ILBM 24Bits, 86x128) selected by user, compose and render them
** into a big backdrop picture, and finally save the generated palette.
**
** Klondike & Reko Tools © Copyright Reko Productions - All Rights Reserved.
**
** $VER: MakeGlobalPalette/English v2.0 (16.06.97) Copyright © 1995-97 Lejardinier Olivier - All Rights Reserverd
**
*/
/*
** ARexx Initialisations
*/
ADDRESS "ADPro"
OPTIONS RESULTS
ReturnCode = 0
/*
** Parse Arguments.
*/
PARSE ARG Mode
/*
** Contants Initializations
*/
NL = '0A'X
DNL = NL || NL
FALSE = 0
TRUE = 1
/*
** Strings initializations.
*/
TITLE_Error = "Error :"
TITLE_Request = "Request :"
TITLE_Confirm = "Confirm :"
TITLE_SelectScaledPic = "Select 1 scaled picture :"
TITLE_SelectPaletteFile = "Global palette destination :"
MSG_Abort = "Abort ?"
MSG_ErrorCode = "Error code ="
MSG_ADProResult = "ADPro result ="
MSG_UnableToSaveADProPrefs = "Unable to load ADPro prefs."
MSG_UnableToRestoreADProPrefs = "Unable to restore ADPro prefs."
MSG_YouMustSelectScaledPic = "You MUST select 1 scaled picture !"
MSG_CheckingScaledPic = "Checking scaled picture"
MSG_MissingScaledPic = "Scaled picture missing :"
MSG_WhatBckgrndColor = "Do you to use DEFAULT or CUSTOM background color ?"
MSG_SelectREDComponent = "Enter RED component :"
MSG_SelectGREENComponent = "Enter GREEN component :"
MSG_SelectBLUEComponent = "Enter BLUE component :"
MSG_NotEnoughtMemoryToComputePalette = "No enought memory to compute palette"
MSG_UnableToCreateBackdrop = "Unable to create backdrop picture"
MSG_LoadingScaledPic = "Loading scaled picture"
MSG_UnableToLoadScaledPic = "Unable to load scaled picture :"
MSG_NoScaledPicLoaded = "None scaled picture loaded
MSG_ComputingPalette = "Computing palette"
MSG_UnableToComputePalette = "Unable to compute palette"
MSG_SavingPalette = "Saving palette"
MSG_UnableToSavePalette = "Unable to save palette :"
GAD_Abort = "Abort"
GAD_ContinueAbort = "Continue|Abort"
GAD_SelectAbort = "Select|Abort"
GAD_DefaultCustomAbort = "Default|Custom|Abort"
GAD_Quit = "Quit"
GAD_OkSelectAbort = "Ok|Select|Abort"
GAD_RetryAbort = "Retry|Abort"
GAD_RetrySkipAbort = "Retry|Skip|Abort"
/*
** Save the current ADPro environment.
*/
TempDefaults = "T:TempADProDefaults"
SAVE_DEFAULTS '"'TempDefaults'"'
IF ( RC ~= 0 ) THEN
DO
Text = MSG_UnableToSaveADProPrefs || MSG_ADProError ADPRO_RESULT
OKAY1 '"'Text'"'
END
/*
** Initializations of new ADPro environment.
*/
CLOSE_RENDER_SCREEN
CLEAR_RENDERED
CLEAR_RAW
PSTATUS "UNLOCKED"
DISPLAYMESSAGE '""'
ADPRO_TO_FRONT
/*
** Get some previously scaled pictures files.
*/
ScaledPicsDir = GetPref( "KADPT.ScaledPicsDir" )
IF ( ( ScaledPicsDir ~= "" ) & ( Mode = "AUTO" ) ) THEN
DO
ScaledPicsBaseName = GetPref( "KADPT.ScaledPicsBaseName" )
ScaledPicPath = AddPart( ScaledPicsDir, AddExt( ScaledPicsBaseName, "001" ) )
RetVal = CheckScaledPics( ScaledPicPath )
IF ( WORD( RetVal, 1 ) ~= 52 ) THEN
DO
ReturnCode = 10
CALL Quit
END
END
ELSE
DO
Continue = FALSE
DO UNTIL ( Continue = TRUE )
IF ( ScaledPicsDir ~= "" ) THEN
GETFILE '"'TITLE_SelectScaledPic'"' '"'ParseDir( ScaledPicsDir )'"' '""'
ELSE
GETFILE '"'TITLE_SelectScaledPic'"'
IF ( RC ~= 0 ) THEN
DO
OKAYN '"'TITLE_Error'"' '"'MSG_YouMustSelectScaledPic'"' '"'GAD_SelectAbort'"'
IF ( RC = 0 ) THEN
CALL ConfirmAbort
END
ELSE
DO
ScaledPicPath = ADPRO_RESULT
RetVal = CheckScaledPics( ScaledPicPath )
IF ( WORD( RetVal, 1 ) = 52 ) THEN
DO
SetPref( "KADPT.ScaledPicsDir", WORD( RetVal, 2 ) )
Continue = TRUE
END
END
END
END
ScaledPicsDir = WORD( RetVal, 2 )
ScaledPicsBaseName = WORD( RetVal, 3 )
NbScaledPics = WORD( RetVal, 1 )
/*
** Request background color.
*/
OKAYN '"'TITLE_Request'"' '"'MSG_WhatBckgrndColor'"' '"'GAD_DefaultCustomAbort'"'
IF ( RC = 0 ) THEN
CALL ConfirmAbort
ELSE
IF ( RC = 1 ) THEN
DO
UserRed = 56
UserGreen = 101
UserBlue = 121
END
ELSE
DO
UserRed = GetPref( "KADPT.UserRed" )
IF ( UserRed = "" ) THEN
UserRed = 56
Continue = FALSE
DO UNTIL ( Continue = TRUE )
GETNUMBER '"'MSG_SelectREDComponent'"' ParseString( UserRed ) 0 255
IF ( RC ~= 0 ) THEN
CALL ConfirmAbort
ELSE
DO
UserRed = ADPRO_RESULT
SetPref( "KADPT.UserRed", UserRed )
Continue = TRUE
END
END
UserGreen = GetPref( "KADPT.UserGreen" )
IF ( UserGreen = "" ) THEN
UserGreen = 101
Continue = FALSE
DO UNTIL ( Continue = TRUE )
GETNUMBER '"'MSG_SelectGREENComponent'"' ParseString( UserGreen ) 0 255
IF ( RC ~= 0 ) THEN
CALL ConfirmAbort
ELSE
DO
UserGreen = ADPRO_RESULT
SetPref( "KADPT.UserGreen", UserGreen )
Continue = TRUE
END
END
UserBlue = GetPref( "KADPT.UserBlue" )
IF ( UserBlue = "" ) THEN
UserBlue = 121
Continue = FALSE
DO UNTIL ( Continue = TRUE )
GETNUMBER '"'MSG_SelectBLUEComponent'"' ParseString( UserBlue ) 0 255
IF ( RC ~= 0 ) THEN
CALL ConfirmAbort
ELSE
DO
UserBlue = ADPRO_RESULT
SetPref( "KADPT.UserBlue", UserBlue )
Continue = TRUE
END
END
END
/*
** Create a backdrop picture.
*/
NbRows = ( NbScaledPics + 3 ) % 4
LOAD_TYPE "REPLACE"
Continue = FALSE
DO UNTIL ( ( Continue = TRUE ) | ( NbRows = 0 ) )
LOADER "BACKDROP" "XXX" "WIDTH" 4*88 "HEIGHT" NbRows*130 "COLOR" UserRed UserGreen UserBlue
IF ( RC ~= 0 ) THEN
DO
IF ( ADPRO_RESULT = "Aborted" ) THEN
CALL ConfirmAbort
ELSE
NbRows = NbRows - 1
END
ELSE
Continue = TRUE
END
IF ( NbRows = 0 ) THEN
DO
OKAYN '"'TITLE_Error'"' '"'MSG_NotEnoughtMemoryToComputePalette'"' '"'GAD_Quit'"'
CALL Quit
END
Continue = FALSE
DO UNTIL ( Continue = TRUE )
LOADER "BACKDROP" "XXX" "WIDTH" 4*88 "HEIGHT" NbRows*130 "COLOR" UserRed UserGreen UserBlue
IF ( RC ~= 0 ) THEN
DO
IF ( ADPRO_RESULT = "Aborted" ) THEN
CALL ConfirmAbort
ELSE
DO
Text = MSG_UnableToCreateBackdrop || ADProResult()
OKAYN '"'TITLE_Error'"' '"'Text'"' '"'GAD_RetryAbort'"'
IF ( RC = 0 ) THEN
CALL ConfirmAbort
END
END
ELSE
Continue = TRUE
END
/*
** Compose all selected scaled pictures files into the backdrop picture.
*/
X = 0
Y = 0
ComposedScaledPics = 0
LOAD_TYPE "COMPOSE"
DO Index = 1 TO NbScaledPics
ScaledPicPath = AddPart( ScaledPicsDir, AddExt( ScaledPicsBaseName, RIGHT( Index, 3, '0' ) ) )
Continue = FALSE
DO UNTIL ( Continue = TRUE )
Text = MSG_LoadingScaledPic FilePart( ScaledPicPath )
DISPLAYMESSAGE '"'Text'"'
LOADER "IFF" ScaledPicPath X+1 Y+1 100 -1 -1 -1
IF ( RC ~= 0 ) THEN
DO
IF ( ADPRO_RESULT = "Aborted" ) THEN
CALL ConfirmAbort
ELSE
DO
Text = MSG_UnableToLoadScaledPic || DNL || ParseString( ScaledPicPath ) || ADProResult()
OKAYN '"'TITLE_Error'"' '"'Text'"' '"'GAD_RetrySkipAbort'"'
IF ( RC = 0 ) THEN
CALL ConfirmAbort
ELSE
IF ( RC = 2 ) THEN
Continue = TRUE
END
END
ELSE
DO
X = X + 88
IF ( X = 4*88 ) THEN
DO
X = 0
Y = Y + 130
END
ComposedScaledPics = ComposedScaledPics + 1
Continue = TRUE
END
END
END
IF ( ComposedScaledPics = 0 ) THEN
DO
OKAYN '"'TITLE_Error'"' '"'MSG_NoScaledPicLoaded'"' '"'GAD_Quit'"'
CALL Quit
END
/*
** Render backdrop picture.
*/
SET_RENDER_MODE Amiga 167940 4*88 NbRows*130 HAM8
DITHER 1
Continue = FALSE
DO UNTIL ( Continue = TRUE )
Text = MSG_ComputingPalette
DISPLAYMESSAGE '"'Text'"'
EXECUTE
IF ( RC ~= 0 ) THEN
DO
IF ( ADPRO_RESULT = "Aborted" ) THEN
CALL ConfirmAbort
ELSE
DO
Text = MSG_UnableToComputePalette || ADProResult()
OKAYN '"'TITLE_Error'"' '"'Text'"' '"'GAD_RetryAbort'"'
IF ( RC = 0 ) THEN
CALL ConfirmAbort
END
END
ELSE
Continue = TRUE
END
/*
** Modify computed palette to match Klondike specifications.
*/
PPOKE 0 UserRed UserGreen UserBlue
PPOKE 1 255 0 0
PPOKE 2 255 255 255
PPOKE 3 0 0 0
PPOKE 20 255 0 0
PPOKE 24 255 0 0
/*
** Save palette file.
*/
IF ( Mode = "AUTO" ) THEN
PalettePath = AddPart( ScaledPicsDir, AddExt( ScaledPicsBaseName, "Palette" ) )
ELSE
DO
Continue = FALSE
DO UNTIL ( Continue = TRUE )
GETFILE '"'TITLE_SelectPaletteFile'"' '"'ParseDir( ScaledPicsDir )'"' '"'AddExt( ScaledPicsBaseName, "Palette" )'"'
IF ( RC ~= 0 ) THEN
CALL ConfirmAbort
ELSE
DO
PalettePath = ADPRO_RESULT
Continue = TRUE
END
END
END
SetPref( "KADPT.PalettePath", PalettePath )
Continue = FALSE
DO UNTIL ( Continue = TRUE )
Text = MSG_SavingPalette
DISPLAYMESSAGE '"'Text'"'
PSAVE PalettePath
IF ( RC ~= 0 ) THEN
DO
IF ( ADPRO_RESULT = "Aborted" ) THEN
CALL ConfirmAbort
ELSE
DO
Text = MSG_UnableToSavePalette || DNL || ParseString( PalettePath ) || ADProResult()
ADDRESS COMMAND 'C:Delete >NIL: FILE="' || PalettePath || '" QUIET'
OKAYN '"'TITLE_Error'"' '"'Text'"' '"'GAD_RetryAbort'"'
IF ( RC = 0 ) THEN
CALL ConfirmAbort
END
END
ELSE
Continue = TRUE
END
/*
** Quit.
*/
Quit:
CLOSE_RENDER_SCREEN
CLEAR_RENDERED
CLEAR_RAW
DISPLAYMESSAGE '""'
IF ( EXISTS( TempDefaults ) ) THEN
DO
LOAD_DEFAULTS '"'TempDefaults'"'
IF ( RC ~= 0 ) THEN
DO
Text = MSG_UnableToRestoreADProPrefs || ADProResult()
OKAY1 '"'Text'"'
END
ADDRESS COMMAND 'C:Delete >NIL: FILE="' || TempDefaults || '" QUIET'
END
EXIT ReturnCode
RETURN
/*
** Functions.
*/
CheckScaledPics:
PARSE ARG ScaledPicPath
RetVal = "0"
Text = MSG_CheckingScaledPic FilePart( ScaledPicPath )
DISPLAYMESSAGE '"'Text'"'
LOAD_TYPE "REPLACE"
Continue01 = FALSE
DO UNTIL ( Continue01 = TRUE )
LOADER "IFF" ScaledPicPath
IF ( RC ~= 0 ) THEN
DO
IF ( ADPRO_RESULT = "Aborted" ) THEN
CALL ConfirmAbort
ELSE
DO
Text = MSG_UnableToLoadScaledPic || DNL || ParseString( ScaledPicPath ) || ADProResult()
IF ( Mode = "AUTO" ) THEN
Gad = GAD_RetryAbort
ELSE
Gad = GAD_RetrySelectAbort
OKAYN '"'TITLE_Error'"' '"'Text'"' '"'Gad'"'
IF ( RC = 0 ) THEN
CALL ConfirmAbort "NOCHECK"
ELSE
IF ( RC = 2 ) THEN
Continue01 = TRUE
END
END
ELSE
DO
XSIZE
ScaledPicWidth = ADPRO_RESULT
YSIZE
ScaledPicHeight = ADPRO_RESULT
IF ( ( ScaledPicWidth = 86 ) & ( ScaledPicHeight = 128 ) ) THEN
DO
ScaledPicsDir = DirPart( ScaledPicPath )
ScaledPicsBaseName = DelExt( FilePart( ScaledPicPath ) )
Continue02 = TRUE
NbScaledPics = 0
Extension = 1
DO UNTIL ( ( Continue02 = FALSE ) | ( NbScaledPics = 52 ) )
FileExtension = RIGHT( Extension, 3, '0' )
ScaledPicPath = AddPart( ScaledPicsDir, AddExt( ScaledPicsBaseName, FileExtension ) )
Text = MSG_CheckingScaledPic FilePart( ScaledPicPath )
DISPLAYMESSAGE '"'Text'"'
IF ( EXISTS( ScaledPicPath ) ) THEN
DO
NbScaledPics = NbScaledPics + 1
Extension = Extension + 1
END
ELSE
Continue02 = FALSE
END
DISPLAYMESSAGE '""'
IF ( NbScaledPics = 52 ) THEN
DO
RetVal = NbScaledPics ScaledPicsDir ScaledPicsBaseName
Continue01 = TRUE
END
ELSE
DO
Text = MSG_MissingScaledPic || DNL || ScaledPicPath
IF ( Mode = "AUTO" ) THEN
Gad = GAD_Abort
ELSE
Gad = GAD_SelectAbort
OKAYN '"'TITLE_Error'"' '"'Text'"' '"'Gad'"'
IF ( RC = 0 ) THEN
CALL ConfirmAbort "NOCHECK"
Continue01 = TRUE
END
END
ELSE
DO
Text = MSG_InvalidScaledPicSize || DNL || ScaledPicPath
IF ( Mode = "AUTO" ) THEN
Gad = GAD_Abort
ELSE
Gad = GAD_SelectAbort
OKAYN '"'TITLE_Error'"' '"'Text'"' '"'Gad'"'
IF ( RC = 0 ) THEN
CALL ConfirmAbort "NOCHECK"
Continue01 = TRUE
END
END
END
RETURN RetVal
/*
** Sub Routines
*/
ADProResult:
ADProResultText = DNL || MSG_ErrorCode RC || NL || MSG_ADProResult ADPRO_RESULT
RETURN ADProResultText
ConfirmAbort:
PARSE ARG Check
IF ( ( Mode = "AUTO" ) & ( Check = "NOCHECK" ) ) THEN
DO
ReturnCode = 20
CALL Quit
END
ELSE
DO
OKAYN '"'TITLE_Confirm'"' '"'MSG_Abort'"' '"'GAD_ContinueAbort'"'
IF ( RC = 0 ) THEN
DO
ReturnCode = 20
CALL Quit
END
RETURN
ConfirmAbort:
PARSE ARG Check
IF ( ( Mode = "AUTO" ) & ( Check = "NOCHECK" ) ) THEN
DO
ReturnCode = 20
CALL Quit
END
ELSE
DO
OKAYN '"'TITLE_Confirm'"' '"'MSG_Abort'"' '"'GAD_ContinueAbort'"'
IF ( RC = 0 ) THEN
DO
ReturnCode = 20
CALL Quit
END
RETURN
ParseString: PROCEDURE
PARSE ARG String
RETURN STRIP( String, 'B', '"' )
ParseDir: PROCEDURE
PARSE ARG Dir
Dir = ParseString( Dir )
Dir = STRIP( Dir, 'T', '/' )
RETURN Dir
DirPart: PROCEDURE
PARSE ARG Path
Path = ParseString( Path )
FNameSepPos = LASTPOS( '/', Path )
IF ( FNameSepPos = 0 ) THEN
RETURN LEFT( Path, LASTPOS( ':', Path ) )
ELSE
RETURN LEFT( Path, FNameSepPos - 1 )
FilePart:
PARSE ARG Path
Path = ParseString( Path )
FNameSepPos = LASTPOS( '/', Path )
IF ( FNameSepPos = 0 ) THEN
FNameSepPos = LASTPOS( ':', Path )
RETURN RIGHT( Path, LENGTH( Path ) - FNameSepPos )
AddPart:
PARSE ARG Dir, Name
LastChar = RIGHT( Dir, 1 )
IF (( LastChar ~= "/" ) & ( LastChar ~= ":" )) THEN
Dir = Dir || "/"
RETURN Dir || Name
AddExt:
PARSE ARG Name, Ext
RETURN Name || "." || Ext
DelExt:
PARSE ARG Name
PointPos = LASTPOS( '.', Name )
if ( PointPos ~= 0 ) THEN
Name = DELSTR( Name, PointPos )
RETURN Name
GetPref: PROCEDURE
PARSE ARG Name
Pref = GETCLIP( Name )
IF ( Pref = "" ) THEN
DO
IF ( OPEN( FileHandle, AddPart( "ENVARC:Klondike_ADPTools", Name ), "READ" ) ) THEN
DO
Pref = READLN( FileHandle )
Dummy = CLOSE( FileHandle )
END
END
RETURN Pref
SetPref: PROCEDURE
PARSE ARG Name, Pref
Dummy = SETCLIP( Name, Pref )
IF ( ~EXISTS( "ENVARC:Klondike_ADPTools" ) ) THEN
ADDRESS COMMAND 'C:MakeDir >NIL: ENVARC:Klondike_ADPTools'
IF ( OPEN( FileHandle, AddPart( "ENVARC:Klondike_ADPTools", Name ), "WRITE" ) ) THEN
DO
Dummy = WRITELN( FileHandle, Pref )
Dummy = CLOSE( FileHandle )
END
RETURN Pref